Home:ALL Converter>Why not to interact with the DOM directly in Angular?

Why not to interact with the DOM directly in Angular?

Ask Time:2018-11-24T03:14:05         Author:devDan

Json Formatter

I have read that it is not wise to interact with the DOM directly both for security and performance. Avoiding using syntax like below to select Elements.

const itemToManipulate = document.getElementById('example');

So I read a good work around is to use ElementRef Directive. But go on to find the Angular Documents advise against this because of tight coupling, what is tight coupling?

Found in documentation here

I settled for using a ViewChild, like so...

@ViewChild('itemToManipulate') public item: ElementRef<any>; 

Does this lead to any unwanted behaviour I should be concerned about (security / performance wise) and is there a best practice for interacting with the DOM, or should this not be done within Angular (6 / 7)?

Thanks in Advance.

Author:devDan,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53451918/why-not-to-interact-with-the-dom-directly-in-angular
yy